// staffInfo.html页面

// 星号标识改变

function staffInfoChange() {

    var staffInfoObj = {}
    // 单个input输入
    $('.staffInfoChange').each(function () {
        if ($(this).val() != '') {
            $(this).parent().children('span').css({'color': '#569f25'})
        } else {
            $(this).parent().children('span').css({'color': 'red'})
        }

        staffInfoObj[$(this).attr('data-class')] = $(this).val()
    })

    // 多个input选择
    $('.staffInfoChangeTwo').each(function () {
        if ($(this).val() != '0') {
            $(this).parent().children('span').css({'color': '#569f25'})
        } else {
            $(this).parent().children('span').css({'color': 'red'})
        }
    })  

    // 形象照片
    $('#submit').css({
        'color':'#fff',
        'background': '#569f25'
    })

    var staffImg = $('#staffImg').children('input').val()

    if (staffImg != '') {
        $('#staffImages').children('.bossFileText').children('span').css({'color': '#569f25'})
    } else {
        $('#staffImages').children('.bossFileText').children('span').css({'color': 'red'})
    }

    staffInfoObj.staffImg = staffImg

    // 专业技能
    var businessSkillId = []
    var businessSkillText = []
    var businessSkillCheck = []
    var businessSkillChecks = []
    $('.businessSkill').each(function () {
        businessSkillId.push($(this).val())
        businessSkillText.push($(this).attr('data-text'))

        if ($(this).prop('checked')) {
            businessSkillCheck.push('checked')
            businessSkillChecks.push('checked')
        } else {
            businessSkillCheck.push('')
        }
    })

    if (businessSkillChecks.length > 0) {
        $('#skillCheck').prev().children('span').css({'color': '#569f25'})
    } else {
        $('#skillCheck').prev().children('span').css({'color': 'red'})
    }

    staffInfoObj.businessSkillId =businessSkillId
    staffInfoObj.businessSkillText = businessSkillText
    staffInfoObj.businessSkillCheck = businessSkillCheck

    // 特长爱好
    var businessHobbyId = []
    var businessHobbyText = []
    var businessHobbyCheck = []
    var businessHobbyChecks = []
    $('.businessHobby').each(function () {
        businessHobbyId.push($(this).val())
        businessHobbyText.push($(this).attr('data-text'))

        if ($(this).prop('checked')) {
            businessHobbyCheck.push('checked')
            businessHobbyChecks.push('checked')
        } else {
            businessHobbyCheck.push('')
        }
    })

    if (businessHobbyChecks.length > 0) {
        $('#hobbyCheck').prev().children('span').css({'color': '#569f25'})
    } else {
        $('#hobbyCheck').prev().children('span').css({'color': 'red'})
    }
    
    staffInfoObj.businessHobbyId = businessHobbyId
    staffInfoObj.businessHobbyText = businessHobbyText
    staffInfoObj.businessHobbyCheck = businessHobbyCheck

    cacheSet('staffInfo',staffInfoObj); // 数据存储
    console.log(staffInfoObj)  
}

// 启用缓存

function staffInfoLocalStorage() {
    return;
    var staffInfoObj = cacheGet('staffInfo'); //获取注册缓存资料
    // 单个input输入
    $('.staffInfoChange').each(function () {
     //   $(this).val(staffInfoObj[$(this).attr('data-class')])
    })

    // 形象照片
    if (staffInfoObj.staffImg != '') {
        $('#staffImg').show().css({'height':'100px'}).prepend('<img src="'+staffInfoObj.staffImg+'" height="100" class="bossFileImgDelete">').children('input').val(staffInfoObj.staffImg)
    }

    // 专业技能

    var businessSkillHtml = '',
        businessSkillVal = [];

    for (var i = 0, len = staffInfoObj.businessSkillText.length; i < len; i++) {
        (function (n) {
            businessSkillHtml += '<span class="businessItem">'+
                                    '<label class="businessValue">'+
                                        '<input type="checkbox" class="businessCheck businessSkill" data-text="'+staffInfoObj.businessSkillText[n]+'" '+staffInfoObj.businessSkillCheck[n]+' value="'+staffInfoObj.businessSkillId[n]+'" onclick="setStaffSkill(this.value),staffInfoChange()">'+' '+
                                        staffInfoObj.businessSkillText[n]+
                                    '</label>'+
                                '</span>'

            if (staffInfoObj.businessSkillCheck[n] != '') {
                businessSkillVal.push(staffInfoObj.businessSkillId[n])
            } 
            
            $("#skillStr").val(businessSkillVal.join(','))
        })(i)
    }
    $('#skillCheck').html(businessSkillHtml)

    // 特长爱好

    var businessHobbyHtml = '',
        businessHobbyVal = [];

    for (var i = 0, len = staffInfoObj.businessHobbyText.length; i < len; i++) {
        (function (n) {
            businessHobbyHtml += '<span class="businessItem">' +
                                    '<label class="businessValue">' +
                                        '<input type="checkbox" class="businessCheck businessHobby" data-text="'+staffInfoObj.businessHobbyText[n]+'" '+staffInfoObj.businessHobbyCheck[n]+' value="'+staffInfoObj.businessHobbyId[n]+'" onclick="setStaffHobby(this.value),staffInfoChange()">' + ' ' +
                                        staffInfoObj.businessHobbyText[n] +
                                    '</label>'+
                                '</span>'

            if (staffInfoObj.businessHobbyCheck[n] != '') {
                businessHobbyVal.push(staffInfoObj.businessHobbyId[n])
            } 
            
            $("#hobbyStr").val(businessHobbyVal.join(','))
        })(i)
    }
    $('#hobbyCheck').html(businessHobbyHtml)

    staffInfoChange()

}

$('#popDetail').on('click', function () {
    staffInfoChange()
})

// 点击返回
$('.prevStep').on('click', function () {
    cacheSet('staffInfo',''); // 清除缓存个人信息
})